﻿using Himp.Base;
using Himp.ShareData;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace Himp.Platform.EntityFrameworkCore
{
    public static class MainDbContextModelBuilderExtensions
    {
        public static void ConfigureMainManagement(this ModelBuilder builder)
        {
            Check.NotNull(builder, "builder");

            //
            //builder.Entity<PsnInfo>(b =>
            //{
            //    b.ToTable(PlatformConsts.DbTablePrefix + nameof(PsnInfo), PlatformConsts.DbSchema);
            //    b.ConfigureByConvention();
            //});

            //
            builder.Entity<Organ>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(Organ), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<OrganGrant>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(OrganGrant), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            ////科室信息
            //builder.Entity<DeptInfo>(b =>
            //{
            //    b.ToTable(PlatformConsts.DbTablePrefix + nameof(DeptInfo), PlatformConsts.DbSchema);
            //    b.ConfigureByConvention();
            //});

            //科室对应属性
            builder.Entity<DeptAssocAttr>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DeptAssocAttr), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            #region 数据字典

            //数据字典
            builder.Entity<DataDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DataDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            //数据分类
            builder.Entity<CatgeDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(CatgeDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            //BizDict
            builder.Entity<BizDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(BizDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<CodgDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(CodgDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<CodgRule>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(CodgRule), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<CodgHistory>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(CodgHistory), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            #endregion

            #region 菜单

            builder.Entity<Menu>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(Menu), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<MenuGrant>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(MenuGrant), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            #region 科室

            builder.Entity<Dept>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(Dept), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<DeptGrant>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DeptGrant), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            #endregion

            #endregion

            builder.Entity<BizSeq>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(BizSeq), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<EventMsgSendRec>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(EventMsgSendRec), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<AttrDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(AttrDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            //builder.Entity<PosInfo>(b =>
            //{
            //    b.ToTable(PlatformConsts.DbTablePrefix + nameof(PosInfo), PlatformConsts.DbSchema);
            //    b.ConfigureByConvention();
            //});

            #region lowcode

            builder.Entity<OpenApiFuncConfig>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(OpenApiFuncConfig), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<StdWordDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(StdWordDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<DataTableColumn>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DataTableColumn), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<DataTableDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DataTableDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<DataTableRestrRule>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DataTableRestrRule), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<AppModule>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(AppModule), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<AppTopic>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(AppTopic), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<DataModelDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DataModelDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<DataModelExtPropertyDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DataModelExtPropertyDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<EventModelDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(EventModelDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<EventModelPropertyDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(EventModelPropertyDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<StdDomainDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(StdDomainDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<DataModelPropertyDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DataModelPropertyDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<StdPhrDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(StdPhrDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<DataFormDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DataFormDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<DataViewContainerDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DataViewContainerDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<DataViewDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DataViewDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<DataViewValueDict>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(DataViewValueDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            #endregion

            #region 工作流

            builder.Entity<AppBizflow>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(AppBizflow), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<AppBiznode>(b =>
            {
                b.ToTable(PlatformConsts.DbTablePrefix + nameof(AppBiznode), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            #endregion

            #region 患者

            builder.Entity<PatnMasterIdx>(b =>
            {
                b.ToTable(PlatformConsts.ShareDataDbTableProfix + nameof(PatnMasterIdx), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<PatnBaseInfo>(b =>
            {
                b.ToTable(PlatformConsts.ShareDataDbTableProfix + nameof(PatnBaseInfo), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<PatnCardInfo>(b =>
            {
                b.ToTable(PlatformConsts.ShareDataDbTableProfix + nameof(PatnCardInfo), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            #endregion

            #region 疾病诊断

            builder.Entity<ClncDiagDict>(b =>
            {
                b.ToTable(PlatformConsts.ShareDataDbTableProfix + nameof(ClncDiagDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<TcmDiseDict>(b =>
            {
                b.ToTable(PlatformConsts.ShareDataDbTableProfix + nameof(TcmDiseDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<TcmsympDict>(b =>
            {
                b.ToTable(PlatformConsts.ShareDataDbTableProfix + nameof(TcmsympDict), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            #endregion

            #region 公共项目

            builder.Entity<PubItem>(b =>
            {
                b.ToTable(PlatformConsts.ShareDataDbTableProfix + nameof(PubItem), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<AgmtItem>(b =>
            {
                b.ToTable(PlatformConsts.ShareDataDbTableProfix + nameof(AgmtItem), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<PubItemAssocChrgitmType>(b =>
            {
                b.ToTable(PlatformConsts.ShareDataDbTableProfix + nameof(PubItemAssocChrgitmType), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<PubItemBilgGrant>(b =>
            {
                b.ToTable(PlatformConsts.ShareDataDbTableProfix + nameof(PubItemBilgGrant), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<PubItemExecGrant>(b =>
            {
                b.ToTable(PlatformConsts.ShareDataDbTableProfix + nameof(PubItemExecGrant), PlatformConsts.DbSchema);
                b.ConfigureByConvention();
            });

            #endregion
        }
    }
}
